<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>发布新投票</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
	<script src="js/vue.min.js"></script>
	<script src="js/vote.js"></script>
	<script src="js/axios.min.js"></script>
</head>
<body>

<div id="app">
	<common>
		<div id="voteManage" class="box">
			<h2>添加新投票</h2>
			<div class="content">
				<form method="post" action="view.html">
					<dl>
						<dt>投票内容：</dt>
						<dd>
							<input type="hidden" name="entityId" value=""/>
							<input v-model="vname" type="text" class="input-text" name="subject.title"  value=""/>
						</dd>
						<dt>投票类型：</dt>
						<dd>
							<input v-model="vtype" type="radio" name="subject.type" value="单选" />单选
							<input v-model="vtype" type="radio" name="subject.type" value="多选" />多选
						</dd>
						<dt>投票选项：</dt>

						<dd id="voteoptions">
							<p v-for="name,i in iname">
								<input v-model="iname[i]" type="text" class="input-text" name="options" />
							</p>
						</dd>


						<dt></dt>
						<dd class="button">
							<input @click.prevent="commit" type="image" src="images/button_submit.gif" />
							<a @click.prevent="iname.push('')" href="#">增加选项</a>
							<a href="index.html">取消操作</a>
						</dd>
					</dl>
				</form>
			</div>
		</div>
	</common>
</div>

<script>
	var v = new Vue({
		el : "#app",
		data:{
			vname:"", vtype:"单选", iname:["",""]
		},
		methods:{
			commit(){
				let p = new URLSearchParams();
				p.append("vname",this.vname);
				p.append("vtype",this.vtype);
				this.iname.forEach(name=>p.append("iname",name));
				axios.post("demovote/vote/create",p).then(res=>{
					if(res.data.code==1){
						location.href="index.html"
					} else {
						// 	自行扩展保存信息的展示， 参考注册
						console.log(res.data.data);
						alert(res.data.msg);
					}
				})
			}
		}
	})
</script>


</body>
</html>

